$(function () {

    var _thisPage = null, _user = null;

    var setphonePage = function () {
        this.init();
    };
    setphonePage.prototype = {
        init: function () {
            this.initData();
            this.bindEvent();
        },
        initData: function () {
            _user = getLocalStorage(STORAGE_MANAGER.user);
            if (_user && _user.id > 0) {

            } else {
                redirect("login.html");
                return false;
            }
        },
        bindEvent: function () {
            //点击回退
            $("#back").on("tap", function () {
                back();
            });

            //清除输入
            $("#clear").on("tap", function () {
                $("input").val("");
            });

            //点击获取验证码
            $("#getVcode").on("tap", function () {
                change_code(this, $("#newPhone"), SMS_TYPE.verify);
            });

            $("#commit").on("tap", function () {
                if ("" == $("#vcode").val()) {
                    $.alert("请填写验证码");
                    return false;
                }
                if (!isVCode($("#vcode").val())) {
                    $.alert("验证码不正确");
                    return false;
                }

                var postData = {
                    "memberId": _user.id,
                    "vcode": $("#vcode").val(),
                    "origin_obj": "",
                    "active_obj": $("#newPhone").val()
                };
                $.ajax({
                    type: "POST",
                    url: CONFIG_MANAGER.RequstUrl + "v1/member/safety/phone",
                    async: true,
                    data: postData,
                    headers: {"token": _user.token},
                    beforeSend: function () {
                        $.showWaiting('等待中...');
                    }
                }).done(function (data) {

                });

            });
        },
    };

    _thisPage = new setphonePage();

});